package admin

import (
	"context"

	"server/internal/svc"
	"server/internal/types"
	"server/models"
	"server/utils"

	"github.com/jinzhu/copier"
	"github.com/zeromicro/go-zero/core/logx"
)

type ShippingTemplateSaveLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewShippingTemplateSaveLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShippingTemplateSaveLogic {
	return &ShippingTemplateSaveLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *ShippingTemplateSaveLogic) ShippingTemplateSave(req *types.ShippingTemplateSaveReq) (resp string, err error) {

	data := &models.ShippingTemplate{}
	copier.Copy(data, req)

	if req.Id == 0 {
		// 创建新角色
		err = utils.InsertData(data)
	} else {
		err = utils.UpdateById(req.Id, data)
	}

	if err != nil {
		return "", err
	}

	return "操作成功", nil
}
